package main

import (
	"strings"
)

func main() {
	println(simplifyPath("/home/../../.."))
}

//	fmt.Printf("%#v\n", i)
func simplifyPath(path string) string {
	strs := strings.Split(path, "/")

	res := make([]string, len(strs))
	i := 0
	for _, str := range strs {
		if str == "" || str == "." {
			continue
		} else if str == ".." {
			if i == 0 {
				continue
			}
			i--
		} else {
			res[i] = str
			i++
		}
	}
	//fmt.Printf("%#v\n", res)
	ans := strings.Builder{}
	for j, str := range res {
		if i == 0 || str == "" {
			ans.WriteString("/")
			break
		}
		ans.WriteString("/")
		ans.WriteString(str)
		if j == i-1 {
			break
		}

	}
	return ans.String()
}
